Fix UTF-8 code units to match the number of bytes#4098
Merged
Conversation
8dd6d5b to
817ec5a
Compare
Collaborator
|
To get typecheck to pass you need to run |
Earlopain
reviewed
Apr 30, 2026
817ec5a to
846dc81
Compare
Collaborator
Author
|
Just FYI: running the command generated other RBI/RBS changes that aren't related to this PR, so I think the files might be out of sync in main despite not causing any type checking failures. I only included the updates for parse result. |
Earlopain
approved these changes
Apr 30, 2026
Collaborator
Earlopain
left a comment
There was a problem hiding this comment.
👍 looks good, thanks!
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I was seeing some weird results for UTF-8 in the Ruby LSP and I realized we actually made a mistake when implementing the code unit offsets. The idea is for this method to return code units (not code points!). That means:
Spec reference: see the comments above each position encoding kind.
We are actually not returning the number of bytes, but the string length, which is incorrect. It's easy to see the mistake in the tests: the location of an emoji (4 bytes) was 1 before (single character).
This PR makes sure that we're returning the number of bytes for UTF-8, which is the amount expected for code units.
Basically, I added a UTF-8 counter that just returns the number of bytes and tried to ensure naming consistency across the counters.